package com.fulu.game.bi.controller.channel;

import com.fulu.game.bi.AssertHelper;
import com.fulu.game.bi.common.controller.BaseController;
import com.fulu.game.bi.common.exception.BizException;
import com.fulu.game.bi.entity.po.channel.Label;
import com.fulu.game.bi.entity.po.channel.LabelGroup;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.channel.label.LabelGroupDisplayVO;
import com.fulu.game.bi.entity.vo.channel.label.LabelGroupQueryVO;
import com.fulu.game.bi.entity.vo.channel.label.LabelGroupSaveVO;
import com.fulu.game.bi.redis.service.channel.LabelGroupService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 标签分组管理
 */
@RestController
@Slf4j
@RequestMapping("/api/v1/label-group")
public class LabelGroupController extends BaseController {

    @Autowired
    private LabelGroupService labelGroupService;

    /**
     * 保存标签分组
     */
    @PostMapping("/save")
    public Result<LabelGroup> save(LabelGroupSaveVO vo) {
        LabelGroup res = labelGroupService.save(vo);

        return Result.success().data(res).msg("保存成功");
    }

    /**
     * 查询标签分组列表
     */
    @PostMapping("/list")
    public Result<PageInfo<LabelGroupDisplayVO>> list(LabelGroupQueryVO vo) {
        PageInfo<LabelGroupDisplayVO> page = labelGroupService.list(vo);

        return Result.success().data(page).msg("查询成功");
    }

    /**
     * 删除标签分组
     */
    @PostMapping("/delete")
    public Result<Label> delete(@RequestParam Integer id) {
        AssertHelper.assertNotNull(id, () -> new BizException("参数不能为空"));
        return labelGroupService.delete(id) ? Result.success() : Result.error().msg("无法删除");
    }

}
